package com.ruoyi;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class B {

	public static String decrypt(byte[] key, byte[] initVector, String encrypted) {
		try {
			IvParameterSpec iv = new IvParameterSpec(initVector);
			SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");

			Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
			cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);

			// byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
			byte[] original = cipher.doFinal(hexStr2Bytes(encrypted));

			return new String(original, "ISO-8859-1");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return null;
	}

	private static byte[] hexStr2Bytes(String hexStr) {
		String str = "0123456789ABCDEF";
		char[] hexs = hexStr.toCharArray();
		byte[] bytes = new byte[hexStr.length() / 2];
		int n;
		for (int i = 0; i < bytes.length; i++) {
			n = str.indexOf(hexs[2 * i]) * 16;
			n += str.indexOf(hexs[2 * i + 1]);
			bytes[i] = (byte) (n & 0xff);
		}
		return bytes;
	}

	private static byte[] getByte(String[] s) {
		byte[] bytes = new byte[s.length];
		for (int i = 0; i < s.length; i++) {
			bytes[i] = (byte) Integer.parseInt(s[i], 16);
		}
		return bytes;
	}

	public static void main(String[] args) {
		String content = "B14710C6D6CC5D9DA540AE4A5B86B6F96966CB3353DF04E7DC57D22E211A3303CF44FCC6FBB6E1C295CA7EB60D87E2ABE4F08E33EBBABB0DAB83B08CB7B911A8FFD9FA7DD5F50C506B57CC7C0FCF9EEA";
		String[] iv = { "f0", "e1", "d2", "c3", "b4", "a5", "96", "87", "78", "69", "5a", "4b", "3c", "2d", "1e",
				"0f" };
		String[] key = { "24", "7e", "11", "86", "28", "ae", "d0", "a6", "ab", "f7", "05", "88", "09", "cf", "2f",
				"3f" };
		String s = decrypt(getByte(key), getByte(iv), content);
		System.out.println(s);
	}

}
